fetch("http://chst.vip:1234/api/getbaicaijiatitle")
    .then(body => body.json())
    .then(res => {
        console.log(res);
        let html = "";
        let qiehuan = document.querySelector("#qiehuan div ul")
        console.log(qiehuan);
        res.result.forEach(item => {
            // console.log(res);
            html +=
                `<li>
        <a href="#" titleId="${item.titleId}">${item.title}</a>
        </li>`
        });
        qiehuan.innerHTML = html;
        let qiehuana = document.querySelectorAll("#qiehuan div ul li a")
        console.log(qiehuana);
        for (var i = 0; i < qiehuana.length; i++) {
            qiehuana[i].onclick = function () {
                for (var a = 0; a < qiehuana.length; a++) {
                    qiehuana[a].style.color = "black"
                }
                this.style.color = "red"
                // main(this.titleId)
                let index = this.getAttribute("titleId")
                main(index)
            }
        }

        function main(titleid) {
            fetch("http://chst.vip:1234/api/getbaicaijiaproduct?titleid=" + titleid)
                .then(boddy => boddy.json())
                .then(ress => {
                    console.log(ress);
                    let html = "";
                    ress.result.forEach(item => {
                        // console.log(ress.result.length);
                        html +=
                            `
                        <li><a href="#">
                        <div class="infoleft">
                            ${item.productImg}
                        </div>
                        <div class="inforight">
                            <h4>
                                ${item.productName}
                            </h4>
                            <div class="jg">
                                ${item.productPrice}
                                <del>1888.0</del>
                            </div>
                            <div class="down">
                                <div class="bar">
                                    <div class="barin"></div>
                                </div>
                                <span class="yiling"></span>
                                <div class="click">
                                    <div class="left">点此领取优惠卷</div>
                                    <div class="right">下单链接</div>

                                </div>
                            </div>
                        </div>
                    </a></li>
                        `
                    })
                    let htmll = document.querySelector("#product .info")
                    htmll.innerHTML = html


                    let barinn = document.querySelectorAll("#product .info li a .inforight .down .bar .barin")
                    let yiling = document.querySelectorAll("#product .info li a .inforight .down .yiling")
                    let barin = $("#product .info li a .inforight .down .bar .barin")
                    barin.animate({
                        width: "3.25rem"
                    }, 6000)
                    let yibaia = 0;
                    let yilingqq = 0;
                    let shengyuqq = 126
                    let yibai = setInterval(function () {
                        for (let a = 0; a <= ress.result.length - 1; a++) {
                            barinn[a].innerHTML = yibaia + "%";
                            // yiling[a].innerHTML = "已领"+yilingqq+"张/剩余"+shengyuqq+"张；"
                            // console.log(yibaia);
                        }
                        if (yibaia >= 100) {
                            clearInterval(yibai)
                        }
                        yibaia++
                       
                    }, 60)
                    let youhui = setInterval(function(){
                        for (let a = 0; a <= ress.result.length - 1; a++) {
                            yiling[a].innerHTML = "已领"+yilingqq+"张/剩余"+shengyuqq+"张"
                            // console.log(yibaia);
                        }
                        if (yilingqq >= 126) {
                            clearInterval(youhui)
                        }
                        yilingqq++
                        shengyuqq--
                    },48)

                })
        }
        main(0)






    })


